package com.tencent.cloud.iov.processor.utils;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;

/**
 * 日志打印工具类
 *
 * 可从 Gradle Console 查看到输出的日志
 *
 * @author showxiao
 * @date 2018/4/18
 */

public class LogHelper {

    private final ProcessingEnvironment mProcessingEnv;

    public LogHelper(ProcessingEnvironment processingEnv) {
        mProcessingEnv = processingEnv;
    }

    public void error(Element element, String message, Object... args) {
        printMessage(Diagnostic.Kind.ERROR, element, message, args);
    }

    public void note(Element element, String message, Object... args) {
        printMessage(Diagnostic.Kind.NOTE, element, message, args);
    }

    private void printMessage(Diagnostic.Kind kind, Element element, String message, Object[] args) {
        if (args.length > 0) {
            message = String.format(message, args);
        }

        mProcessingEnv.getMessager().printMessage(kind, message, element);
    }
}
